#ifndef MAIN_H
#define MAIN_H

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <sys/param.h>

#include "esp_types.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_log.h"
#include "esp_event_base.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "esp_timer.h"
#include "esp_adc_cal.h"
#include "esp_task_wdt.h"

#include "nvs_flash.h"
#include "tcpip_adapter.h"

#include "lwip/err.h"
#include "lwip/sockets.h"
#include "lwip/sys.h"
#include <lwip/netdb.h>

#include "freertos/queue.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "driver/periph_ctrl.h"
#include "driver/timer.h"
#include "driver/gpio.h"
#include "driver/adc.h"
#include "driver/uart.h"
#include "driver/ledc.h"


#include "Chip.h"
#include "temperature_control_sub_module/TempADC.h"
#include "temperature_control_sub_module/pid.h"
#include "temperature_control_sub_module/FanCtrl.h"

#include "LCD/HT162X.h"
#include "LCD/HT162X_Lcd.h"
#include "LCD/Lcd_AWS_Interface.h"
#include "LCD/UI.h"
#include "Encoder.h"
// #include "WiFi_STA.h"
// #include "gatts_table_creat_demo.h"
// #include "AWS_Mould.h"
#include "Buzzer.h"
#include "CRC16.h"


#include "lwip/err.h"
#include "lwip/sys.h"
#include <esp_wifi.h>
#include <esp_event.h>
#include <esp_log.h>
#include <esp_system.h>
#include <nvs_flash.h>
#include <sys/param.h>
#include "esp_netif.h"
// #include "esp_eth.h"
// #include "protocol_examples_common.h"
#include "esp_task_wdt.h"

#include "sdkconfig.h"

#include "wifi/softap.h"
#include "wifi/http_server.h"
#include "wifi/station.h"
#include "wifi/ota.h"
#include "ble/gatt.h"
#include "mac.h"
#include "nvs.h"
#include "load_cert.h"
#include "Maintain.h"
#include "FactoryTest.h"
#include "heartbeat.h"
#include "MCU_Mold/MCU_F_C_Convert.h"

#include "../lot_State.h"
#include "../Grill_State.h"
#include "aws_esp32/aws_iot_client_main.h"
#include "aws_esp32/MqttPublish_Data.h"
#include "aws_esp32/MqttSubscribe_Data.h"



//softap ssid password
#define EXAMPLE_ESP_AP_SSID      "BIC_d18482f0"
#define EXAMPLE_ESP_AP_PASS      "f008d18482f0"
//wifi station ssid password
#define EXAMPLE_ESP_WIFI_SSID      "Meta"
#define EXAMPLE_ESP_WIFI_PASS      "metatype1234"

//wifi station ssid password
extern volatile char* g_wifi_ssid;
extern volatile char* g_wifi_password;
//mac
extern volatile unsigned int ID_first_four;
extern volatile unsigned int ID_mid_four;
extern volatile unsigned int ID_last_four;

extern volatile unsigned char global_tmr1_alert;//定时器1报警
extern volatile unsigned char global_tmr2_alert;//定时器2报警
extern volatile unsigned char global_rtd1_alert;//肉探针1报警
extern volatile unsigned char global_rtd2_alert;//肉探针2报警


typedef enum
{
    disconnect  = 0,           
    connected  = 1,
} station_state_type;
typedef enum
{
    no_inform  = 0,           
    get_inform  = 1,
} station_information_type;

struct
{
    station_information_type station_inform_state;
    station_state_type station_state;
    station_state_type aws_connect_state;
    station_information_type nvs_save_inform;
    station_information_type nvs_save_nickname;
    station_information_type nvs_clear_inform;
    station_information_type aws_received_command;
    station_information_type aws_cert;
} wireless_state;

volatile unsigned char nick_name[100];
volatile unsigned char ca_cert[1300];
volatile unsigned char private_cert[1700];

typedef enum
{
    Probe_NotValid = 0, //(默认)肉探针探测无效
    Probe_Valid,
}Probe_Detect_E;
typedef enum
{
    Probe_AlarmDetect_None, //报警探测无效
    Probe_AlarmDetect,
}Probe_AlarmDetect_E;
typedef struct 
{
    uint16_t v_read;
    uint16_t v_write;
    Probe_Detect_E v_detect;
    Probe_AlarmDetect_E alarm_Detect;
    void (*Alarm_Handled)(void); //报警处理
    uint8_t Alert_State; //1:已报警处理, 0:未报警
}UI_Probe_E;


#endif
